package com.yzd.learnjava.io;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

import com.yzd.learnjava.util.Print;

public class LargeMappedFiles {
	static int length = 0x8ffffff;
	public static void main(String[] args) throws IOException, IOException {
		MappedByteBuffer out = new RandomAccessFile("test.dat", "rw").getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length);
		for(int i = 0 ; i < length; i++) {
			out.put((byte)'x');
		}
		Print.print("Finishing writing");
		for(int i = length / 2 ; i < length / 2 + 6; i++ ) {
			Print.printnb((char)out.get(i));
		}
	}
}
